import axios from "axios";
import Vue from "vue";
import { Message } from "element-ui";
const params = {
  version: "v9",
  appid: "39691687",
  appsecret: "O6EwHR4Q"
};
const instance = axios.create({
  baseURL: "http://www.tianqiapi.com",
  timeout: 30000,
  params: params,
  transformRequest() {}
});
export const vueInstance = new Vue({
  methods: {
    intercept(config) {
      return new Promise(resolve => {
        resolve(config);
      });
    },
    responseTrans(res) {
      console.log(res);
      if (res.data.errcode === 100) {
        Message.error(res.data.errmsg);
      }
      return new Promise(resolve => {
        resolve(res);
      });
    }
  }
});
const { responseTrans, intercept } = vueInstance;
instance.interceptors.response.use(responseTrans);
instance.interceptors.request.use(intercept);
export default instance;
